package com.zhku.shoppingspringboot.controller;

import com.zhku.shoppingspringboot.common.R;
import com.zhku.shoppingspringboot.pojo.dto.AddAddressDTO;
import com.zhku.shoppingspringboot.pojo.entity.Address;
import com.zhku.shoppingspringboot.service.IAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hwy
 * @date 2025-01-02 00:27
 */
@RestController
@RequestMapping("/member/address")
@Slf4j
@Api(tags = "收货地址管理")
public class AddressController {
    @Autowired
    private IAddressService iAddressService;
    @ApiOperation("添加-收货地址")
    @PostMapping("")
    public R<Long> addAddress(
            @RequestBody
            AddAddressDTO addAddressDTO
    ){
        Long id = iAddressService.addAddress(addAddressDTO);
        return R.success(id);
    }

    @ApiOperation("获取收货地址")
    @GetMapping
    public R<List<Address>> getAddress(){
        return R.success(iAddressService.getAddress());
    }

    @ApiOperation("修改收货地址")
    @PutMapping
    public R<Long> modifyAddress(
            @RequestBody
            Address address
    ){
        return R.success(iAddressService.modifyAddress(address));
    }

    @ApiOperation("删除收货地址")
    @DeleteMapping("/{id}")
    public R<Long> deleteAddress(
            @PathVariable("id")
            Long id
    ){
        return R.success(iAddressService.deleteAddress(id));
    }
}
